<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <style>
        body {
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>
<body>

<script src="../lib/three.js"></script>
<script>
    const scene = new THREE.Scene()

    const geometry = new THREE.BufferGeometry()
    const vertices = new Float32Array([
        0, 0, 0, // 顶点1坐标
        80, 0, 0, // 顶点2坐标
        80, 80, 0, // 顶点3坐标
        0, 80, 0, // 顶点4坐标
    ])
    geometry.attributes.position = new THREE.BufferAttribute(vertices, 3)

    const normals = new Float32Array([
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,
    ])
    geometry.attributes.normal = new THREE.BufferAttribute(normals, 3)

    // 索引
    const indexes = new Uint16Array([
        0, 1, 2,
        0, 2, 3,
    ])
    geometry.index = new THREE.BufferAttribute(indexes, 1)

    const material = new THREE.MeshBasicMaterial({
        color: 0x0000ff,
        side: THREE.DoubleSide, // 两面可见
    })
    const mesh = new THREE.Mesh(geometry, material)
    scene.add(mesh)

    const point = new THREE.PointLight(0xffffff)
    point.position.set(200, 200, 200)
    scene.add(point)

    const ambient = new THREE.AmbientLight(0xffffff)
    scene.add(ambient)

    const axesHelper = new THREE.AxesHelper(200)
    scene.add(axesHelper)

    const width = window.innerWidth
    const height = window.innerHeight
    const k = width / height
    const s = 100
    const camera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, 1, 1000)
    camera.position.set(200, 200, 200)
    camera.lookAt(scene.position)

    const renderer = new THREE.WebGLRenderer()
    renderer.setSize(width, height)
    renderer.setClearColor(0xb9d3ff, 1)
    document.body.appendChild(renderer.domElement)

    renderer.render(scene, camera)
</script>
</body>
</html>
